﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Himp.Platform
{
    public class OpenApiService : PlatformAppService, IOpenApiService
    {
        private ILogger<OpenApiService> _logger;
        private readonly IServiceProvider _serviceProvider;

        public OpenApiService(IServiceProvider serviceProvider
            , ILogger<OpenApiService> logger)
        {
            _serviceProvider = serviceProvider;
            _logger = logger;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="infNo"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<InternalApiOutput> Post(string infNo, string input)
        {
            _logger.LogInformation(infNo, input);
            InternalApiOutput internalApiOutput = new InternalApiOutput();
            internalApiOutput.InfStasno = 0;
            internalApiOutput.RefMsgId = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            internalApiOutput.ResTime = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            List<Dictionary<string, object>> output = new List<Dictionary<string, object>>();

            if (infNo == "1001")
            {
                Dictionary<string,object> keyValuePairs1 = new Dictionary<string, object>();

                keyValuePairs1.Add("spler", "兴仁市xxx");
                keyValuePairs1.Add("variety", "xx");
                keyValuePairs1.Add("originPlace", "-");
                keyValuePairs1.Add("destinationPlace", "-");
                keyValuePairs1.Add("carno", "贵Exxx41");
                keyValuePairs1.Add("cardno", "741B3EAA");
                keyValuePairs1.Add("grossWeight", "97.40");
                keyValuePairs1.Add("grossWeightTime", "2021-01-29 09:19:57.247");
                keyValuePairs1.Add("tareWeight", "24.58");
                keyValuePairs1.Add("tareWeightTime", "2021-01-29 09:48:19.080");
                keyValuePairs1.Add("netWeight", "72.82");

                Dictionary<string, object> keyValuePairs2 = new Dictionary<string, object>();
                keyValuePairs2.Add("spler", "晴隆县xxx");
                keyValuePairs2.Add("variety", "xx");
                keyValuePairs2.Add("originPlace", "-");
                keyValuePairs2.Add("destinationPlace", "-");
                keyValuePairs2.Add("carno", "贵Exxx42");
                keyValuePairs2.Add("cardno", "741B3EAA");
                keyValuePairs2.Add("grossWeight", "97.40");
                keyValuePairs2.Add("grossWeightTime", "2021-01-29 09:19:57.247");
                keyValuePairs2.Add("tareWeight", "24.58");
                keyValuePairs2.Add("tareWeightTime", "2021-01-29 09:48:19.080");
                keyValuePairs2.Add("netWeight", "72.82");

                Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
       
                keyValuePairs3.Add("spler", "兴仁市xxx");
                keyValuePairs3.Add("variety", "xx");
                keyValuePairs3.Add("originPlace", "-");
                keyValuePairs3.Add("destinationPlace", "-");
                keyValuePairs3.Add("carno", "贵Exxx43");
                keyValuePairs3.Add("cardno", "741B3EAA");
                keyValuePairs3.Add("grossWeight", "97.40");
                keyValuePairs3.Add("grossWeightTime", "2021-01-29 09:19:57.247");
                keyValuePairs3.Add("tareWeight", "24.58");
                keyValuePairs3.Add("tareWeightTime", "2021-01-29 09:48:19.080");
                keyValuePairs3.Add("netWeight", "72.82");

                output.Add(keyValuePairs1);
                output.Add(keyValuePairs2);
                output.Add(keyValuePairs3);
            }

            internalApiOutput.Output = Newtonsoft.Json.JsonConvert.SerializeObject(output);

            return internalApiOutput;
        }
    }
}
